import 'dart:io';

import 'package:flutter/gestures.dart';
import 'package:flutter/services.dart';

/// Author: Blake
/// Created: 2023-09-18
class GestureConflictTracker extends PanGestureRecognizer {
  final BasicMessageChannel _channel = const BasicMessageChannel(
    'com.gateio.flutter.gesture.conflic',
    StandardMessageCodec(),
  );

  @override
  void rejectGesture(int pointer) {
    super.rejectGesture(pointer);
    _notifyGesture(true);
  }

  @override
  void acceptGesture(int pointer) {
    super.acceptGesture(pointer);
    _notifyGesture(false);
  }

  void _notifyGesture(bool isAccept) {
    // 仅在iOS平台下调用相关方法
    if (Platform.isIOS) {
      try {
        _channel.send(isAccept);
      } catch (e) {
        // 忽略异常
      }
    }
  }
}